package com.business.system.official.toursism.websitecomment.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.business.system.official.toursism.websitecomment.entity.WebsiteComment;
import com.business.system.official.toursism.websitecomment.manager.WebsiteCommentManager;
import com.business.system.official.toursism.websitecomment.mapper.WebsiteCommentMapper;
import com.business.system.official.toursism.websitecomment.vo.WebsiteCommentBriefListVO;
import com.business.system.official.toursism.websitecomment.vo.WebsiteCommentBriefVO;
import com.business.system.official.toursism.websitecomment.vo.WebsiteCommentDetailListVO;
import com.business.system.official.toursism.websitecomment.vo.WebsiteCommentDetailVO;
import com.business.system.official.toursism.websitecomment.vo.data.WebsiteCommentBriefData;
import com.business.system.official.toursism.websitecomment.vo.data.WebsiteCommentDetailData;
import com.business.system.official.toursism.websitenews.entity.WebsiteNews;
import com.business.system.official.toursism.websitenews.manager.WebsiteNewsManager;
import com.seed.core.exception.ManagerException;
import com.seed.core.pojo.manager.impl.SeedSystemManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 评论
 * @author CodeGenerator
 * @date   2025-01-25
 * @version V1.0
 */
@Slf4j
@Transactional(rollbackFor = ManagerException.class)
@Service("websiteCommentManager")
public class WebsiteCommentManagerImpl extends SeedSystemManagerImpl<WebsiteCommentMapper, WebsiteComment> implements WebsiteCommentManager {
    @Autowired
    private WebsiteNewsManager websiteNewsManager;
    @Autowired
    private ISysUserService userService;

    /**
     * 根据id获取详情VO data
     *
     * @param websiteCommentId 对象id
     * @return 详情VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailData convertDetailData(String websiteCommentId) throws ManagerException {
        WebsiteComment websiteComment = this.getById(websiteCommentId);
        return this.convertDetailData(websiteComment);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteComment model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailData convertDetailData(WebsiteComment websiteComment) throws ManagerException {
        WebsiteCommentDetailData websiteCommentDetailData = new WebsiteCommentDetailData();
        try {
            BeanUtils.copyProperties(websiteComment, websiteCommentDetailData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteComment);
        }
        // 封装缺失数据
        WebsiteNews websiteNews = websiteNewsManager.getById(websiteCommentDetailData.getNewsId());
        websiteCommentDetailData.setNewsTitle(websiteNews.getNewsTitle());
        SysUser sysUser = userService.getById(websiteCommentDetailData.getUserId());
        websiteCommentDetailData.setUserName(sysUser.getUsername());
        return websiteCommentDetailData;
    }

    /**
     * 根据id获取详情VO
     *
     * @param websiteCommentId 对象id
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailVO getDetailVO(String websiteCommentId) throws ManagerException {
        WebsiteCommentDetailData websiteCommentDetailData = this.convertDetailData(websiteCommentId);
        return new WebsiteCommentDetailVO(websiteCommentDetailData);
    }

    /**
     * 根据对象获取详情VO
     *
     * @param websiteComment 对象
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailVO getDetailVO(WebsiteComment websiteComment) throws ManagerException {
        WebsiteCommentDetailData websiteCommentDetailData = this.convertDetailData(websiteComment);
        return new WebsiteCommentDetailVO(websiteCommentDetailData);
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteCommentDetailData> getConvertDetailListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteComment::getId, ids);
        List<WebsiteComment> websiteCommentList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteCommentList);
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteCommentDetailData> listConvertDetailData(Wrapper<WebsiteComment> queryWrapper) throws ManagerException {
        List<WebsiteComment> websiteCommentList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteCommentList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteCommentList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteCommentDetailData> listConvertDetailData(List<WebsiteComment> websiteCommentList) throws ManagerException {
        List<WebsiteCommentDetailData> websiteCommentDetailDataList = new ArrayList<>();
        for (WebsiteComment websiteComment : websiteCommentList) {
            websiteCommentDetailDataList.add(this.convertDetailData(websiteComment));
        }
        return websiteCommentDetailDataList;
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailListVO getDetailListVOByIds(List<String> ids) throws ManagerException {
        return new WebsiteCommentDetailListVO(this.getConvertDetailListVOByIds(ids));
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailListVO getDetailListVO(Wrapper<WebsiteComment> queryWrapper) throws ManagerException {
        return new WebsiteCommentDetailListVO(this.listConvertDetailData(queryWrapper));
    }

    /**
     * 根据对象list获取详情VO data list
     *
     * @param websiteCommentList 对象list
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentDetailListVO getDetailListVO(List<WebsiteComment> websiteCommentList) throws ManagerException {
        return new WebsiteCommentDetailListVO(this.listConvertDetailData(websiteCommentList));
    }

    /**
     * 根据id获取简略VO data
     *
     * @param websiteCommentId 对象id
     * @return 简略VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefData convertBriefData(String websiteCommentId) throws ManagerException {
        WebsiteComment websiteComment = this.getById(websiteCommentId);
        return this.convertBriefData(websiteComment);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteComment model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefData convertBriefData(WebsiteComment websiteComment) throws ManagerException {
        WebsiteCommentBriefData websiteCommentBriefData = new WebsiteCommentBriefData();
        try {
            BeanUtils.copyProperties(websiteComment, websiteCommentBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteComment);
        }
        return websiteCommentBriefData;
    }

    /**
     * 根据id获取简略VO
     *
     * @param websiteCommentId 对象id
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefVO getBriefVO(String websiteCommentId) throws ManagerException {
        WebsiteCommentBriefData websiteCommentBriefData = this.convertBriefData(websiteCommentId);
        return new WebsiteCommentBriefVO(websiteCommentBriefData);
    }

    /**
     * 根据对象获取简略VO
     *
     * @param websiteComment 对象
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefVO getBriefVO(WebsiteComment websiteComment) throws ManagerException {
        WebsiteCommentBriefData websiteCommentBriefData = this.convertBriefData(websiteComment);
        return new WebsiteCommentBriefVO(websiteCommentBriefData);
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteCommentBriefData> listConvertBriefDataByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteComment::getId, ids);
        List<WebsiteComment> websiteCommentList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteCommentList);
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteCommentBriefData> listConvertBriefData(Wrapper<WebsiteComment> queryWrapper) throws ManagerException {
        List<WebsiteComment> websiteCommentList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteCommentList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteCommentList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteCommentBriefData> listConvertBriefData(List<WebsiteComment> websiteCommentList) throws ManagerException {
        List<WebsiteCommentBriefData> websiteCommentBriefDataList = new ArrayList<>();
        for (WebsiteComment websiteComment : websiteCommentList) {
            websiteCommentBriefDataList.add(this.convertBriefData(websiteComment));
        }
        return websiteCommentBriefDataList;
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefListVO getBriefListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteComment::getId, ids);
        List<WebsiteComment> websiteCommentList = this.list(queryWrapper);
        return new WebsiteCommentBriefListVO(this.listConvertBriefData(websiteCommentList));
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefListVO getBriefListVO(Wrapper<WebsiteComment> queryWrapper) throws ManagerException {
        List<WebsiteComment> websiteCommentList = this.list(queryWrapper);
        return new WebsiteCommentBriefListVO(this.listConvertBriefData(websiteCommentList));
    }

    /**
     * 根据对象list获取简略VO data list
     *
     * @param websiteCommentList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteCommentBriefListVO getBriefListVO(List<WebsiteComment> websiteCommentList) throws ManagerException {
        return new WebsiteCommentBriefListVO(this.listConvertBriefData(websiteCommentList));
    }
}
